package com.mingserve.raw.domain.dto;

import com.mingserve.common.core.utils.DateUtils;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 查询条件
 */
@Data
public class SelectDto
{
    /**
     * 超级表第一列时间戳，默认Ts为当前系统时间
     */
    private Long ts;
    /**
     * 事件时间
     */
    private Long eventTime;
    /**
     * IoT设备编码
     */
    private String deviceCode;
    /**
     * 测点编码
     */
    private String pointCode;
    private String axial;
    private Long limit;
    private Long offset;
    private Long pageNum;
    private Long pageSize;
    private Long beginTime;
    private Long endTime;
    private String date;
    private Integer runningStatus;
    private String physicalType;
    /**
     * 原始信号 raw 包络信号 env
     */
    private String signalType;
    private String featureType;
    private String typeCode;
    private String tokenCode;
    private String thresholdType;
    /** 请求参数 */
    private Map<String, Object> params = new HashMap<>();

    public Long getLimit()
    {
        if (pageSize != null) {
            limit = pageSize;
        }
        return limit;
    }
    public Long getOffset()
    {
        if (pageNum != null && pageSize != null) {
            offset = (pageNum - 1) * pageSize;
        }
        return offset;
    }
    public Long getBeginTime()
    {
        if (getParams().containsKey("beginTime")) {
            return DateUtils.getTimestamp(getParams().get("beginTime").toString());
        } else if (getEventTime() == null && date != null) {
            return DateUtils.getTimestamp(DateUtils.getStartTime(date));
        }
        return beginTime;
    }
    public Long getEndTime()
    {
        if (getParams().containsKey("endTime")) {
            return DateUtils.getTimestamp(DateUtils.getEndTime(getParams().get("endTime").toString()));
        } else if (getEventTime() == null && date != null) {
            return DateUtils.getTimestamp(DateUtils.getEndTime(date));
        }
        return endTime;
    }
    public String getAxial()
    {
        if (axial == null) {
            axial = "x";
        }
        return axial;
    }
    public String getSignalType()
    {
        if (signalType == null) {
            signalType = "raw";
        }
        return signalType;
    }
    public String getTypeCode()
    {
        if (typeCode != null) {
            typeCode = typeCode.toLowerCase();
        }
        return typeCode;
    }
}
